<?php
ob_start();

include_once "header.php";

/*
	FalconKMS Killmail Submission Handler
	Version 1.0-BETA
	Author: Geoff Wilson (g.a.wilson at ncl.ac.uk)
	
	Manages submission of kill mails, access levels are as follows:
	
	0 - Anyone Can Submit
	1 - Must be logged in, anyone logged in can post
	2 - Must be logged in, and have access to Submit
	3 - Shared Password Protection (ignores logins)
*/

require "parser.php";
?>

<tr>
	<th>Submit a Killmail</th>
</tr>
<tr>
	<td>

<?php
if (isset($_POST['killmail']))
{
	if (($killboardSettings['submitLevel'] != 3) || (sha1($_POST['password']) == $killboardSettings['submitPassword']))
	{
		$parser = new Parser($_POST['killmail']);
		$result = $parser->newParser();
		switch ($result)
		{
			case 1:
			echo ("<p><b>Killmail Posted Sucessfully</b></p>");
			break;
				
			case 0:
			echo ("<p><b>Invalid Killmail</b></p>");
			break;
				
			// Should NEVER hit default case.
			default:
			echo ("<p><b>Parser did not respond, or returned invalid status code</b></p>");
		}
	}
	else
	{
		echo ("<p><b>Invalid Password</b></p>");
	}

}

switch ($killboardSettings['submitLevel'])
{
	case 0:
	echo('
	<form action="submit.php" method="post">
	<textarea  cols="60" rows="20" name="killmail"></textarea>
	<br /><br /><input type="submit" name="submit" value="Submit Mail" />
	</form>');
	break;
	
	case 1:
	if (isset($_SESSION['loggedIn']))
	{
		echo('
		<form action="submit.php" method="post">
		<textarea  cols="60" rows="20" name="killmail"></textarea>
		<br /><br /><input type="submit" name="submit" value="Submit Mail" />
		</form>');
	}
	else
	{
		echo ('<p>You must be logged in to view this page');
	}
	break;
	
	case 2:
	if ((isset($_SESSION['canPost'])) && ($_SESSION['canPost']  == 1))
	{
		echo('
		<form action="submit.php" method="post">
		<textarea  cols="60" rows="20" name="killmail"></textarea>
		<br /><br /><input type="submit" name="submit" value="Submit Mail" />
		</form>');
	}
	else
	{
		echo ('<p>You must be authorized by the killboard administration to post here</p>');
	}
	break;
	
	case 3:
		echo('
		<form action="submit.php" method="post">
		<textarea  cols="60" rows="20" name="killmail"></textarea>
		<br /><br />Password: <input class="text-box" type="password" name="password" />
		<br /><br /><input type="submit" name="submit" value="Submit Mail" />
		</form>');
	break;
}

?>

	</td>
</tr>

<?php
require "footer.php";

ob_end_flush();
?>

